<?php
include_once 'MY/lib_splitword_full.php';

class SplitController extends Zend_Controller_Action{
    function init(){
		if($_SESSION['user']==""){
			echo "<script>window.location='../user/login';</script>";exit;
		}
		$this->registry = Zend_Registry::getInstance();
		$this->view = $this->registry['view'];
		$this->view->baseUrl = $this->_request->getBaseUrl();
                $this->view->template = "index";
	}

        public function indexAction(){
            echo $this->view->render('split/index.html');
        }

        public function splitAction(){
        	$filter=new Zend_Filter_StripTags();
            $str=$filter->filter($this->_request->getPost('title'));

			$cws = scws_new();
			$cws->set_charset('utf8');
			$cws->send_text($str);

		    // segment
		    while ($res = $cws->get_result())
		    {
		        foreach ($res as $tmp)
		        {
		            if ($tmp['len'] == 1 && $tmp['word'] == "\r")
		                continue;
		            if ($tmp['len'] == 1 && $tmp['word'] == "\n")
		                echo $tmp['word'];
		            else
		                printf("%s ", $tmp['word']);
		        }
		        flush();
		    }
		  $cws->close();
        }
}
?>
